<template>
  <div id="hello">
    <template v-if="route.path != '/submit' && route.path != '/watch'">
      <BasicLayout />
    </template>
    <template v-else>
      <RouterView />
    </template>
  </div>
</template>
<script setup name="App" lang="ts">
import BasicLayout from "@/layouts/BasicLayout.vue";
import { useRouter, useRoute } from "vue-router";
import { useUser } from "@/store/user";
import { storeToRefs } from "pinia";
import userRole from "@/access/permissionEnum";
import checkPermission from "@/access/checkPermission";
import message from "@arco-design/web-vue/es/message";
import { onMounted } from "vue";

let router = useRouter();
let route = useRoute();
let user = useUser();

onMounted(async () => {
  await user.getLoginUser();
});
let { loginUser, defaultRoutes } = storeToRefs(user);
router.beforeEach(async (to, from, next) => {
  if (to.meta?.access == userRole.NOT_LOGIN) {
    if (to.meta?.access == userRole.NOT_LOGIN && to.meta?.isOnly == true) {
      if (loginUser.value.userRole != userRole.NOT_LOGIN) {
        next("/errLogin");
        return;
      } else {
        defaultRoutes.value[0] = String(from.path);
        next();
        return;
      }
    }
  } else {
    if (/^register/.test(to.path) || /^register/.test(from.path)) {
      next();
      return;
    }
    if (!checkPermission(loginUser.value, to.meta?.access as string)) {
      if (loginUser.value.userRole == userRole.ADMIN) {
        defaultRoutes.value[0] = String(to.path);
        next();
        return;
      } else if (loginUser.value.userRole != userRole.NOT_LOGIN) {
        next("/nopower");
        return;
      } else {
        message.error("请登录");
        next("/login");
        return;
      }
    }
  }
  defaultRoutes.value[0] = String(to.path);
  next();
});
</script>
<style>
/**修改全局的滚动条*/
/**滚动条的宽度*/
::-webkit-scrollbar {
  width: 10px;
}

::-webkit-scrollbar-thumb {
  background: #d9d9d9;
  border-radius: 3px;
}

/*表格*/
.el-table__body-wrapper::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

.el-table__body-wrapper::-webkit-scrollbar-thumb {
  background-color: #a1a3a9;
  border: 1px #d9d9d9 solid;
}
</style>
